package io.github.jarvisjin.finexpr.operator;

import io.github.jarvisjin.finexpr.expr.ExprException;

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.List;

/**
 * @ClassName LtOperator
 * @Description 小于符号
 * @Author XiaoJiaLin
 * @Date 2022/9/4 21:53
 * @Version 1.0.0
 **/
public class LtOperator  extends Operator {

   public static final String SYMBOL = "<";

   private static LtOperator instance = new LtOperator();

   private LtOperator() {
      super(SYMBOL, 2, true, OperatorPrecedenceCode.PLUS_MINUS);
   }

   /**
    * @param args 参数
    * @param mc
    * @return 结果为真返回 BigDecimal.ONE 结果为 假返回BigDecimal.ZERO
    */
   @Override
   public BigDecimal apply(List<BigDecimal> args, MathContext mc) {
      if (mc == null)
         throw new ExprException("the MathContext cannot be null!");
      for(BigDecimal arg : args) {
         if(arg == null){
            return  null;
         }
      }
      //小于就返回-1 等于返回 0；大于返回1
      int result = args.get(0).compareTo(args.get(1));
      if(result == -1){
         return BigDecimal.ONE ;
      }
      return BigDecimal.ZERO ;

   }

   public static LtOperator getInstance() {
      return instance;
   }

}
